home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug172 / mapch.c < prev    next >
C/C++ Source or Header  |  1986-02-05  |  2KB  |  76 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     LEX - A Lexical Analyser Generator
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      Jan 30, 1985
  6.   DESCRIPTION:     A Lexical Analyser Generator. From UNIX
  7.   KEYWORDS:     Lexical Analyser Generator YACC C PREP
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      MAPCH.C
  10.   WARNINGS:     This program is not for the casual user. It will
  11.          be useful primarily to expert developers.
  12.   CRC:         N/A
  13.   SEE-ALSO:     YACC and PREP
  14.   AUTHORS:     Scott Guthery 11100 leafwood lane Austin, TX 78750
  15.   COMPILERS:     DESMET-C
  16.   REFERENCES:     UNIX Systems Manuals
  17. */
  18. /*
  19.  * Bob Denny     28-Aug-82 Move stdio dependencies to lexerr(), lexget(),
  20.  *                           lexech() and mapch(). This is one of 4 modules in 
  21.  *                           lexlib which depend upon the standard I/O package.
  22.  * Scott Guthery 20-Nov-83 Adapt for IBM PC & DeSmet C
  23.  */
  24.  
  25. /*
  26.  * mapch -- handle escapes within strings
  27.  */
  28.  
  29. #include <stdio.h>
  30. #include <lex.h>
  31.  
  32. extern int yyline;
  33.  
  34. mapch(delim, esc)
  35. {
  36.         register c, octv, n;
  37.  
  38.         if ((c = lexchar())==delim)
  39.                 return(EOF);
  40.         if (c==EOF || c=='\n') {
  41.                 lexerror("Unterminated string");
  42.                 ungetc(c, lexin);
  43.                 return(EOF);
  44.         }
  45.         if (c!=esc)
  46.                 return(c);
  47.         switch (c=lexchar()) {
  48.         case 't':
  49.                 return('\t');
  50.         case 'n':
  51.                 return('\n');
  52.         case 'f':
  53.                 return('\f');
  54.         case '\"': case '\'':
  55.                 return(c);
  56.         case 'e':
  57.                 return('\e');
  58.         case 'p':
  59.                 return(033);
  60.         case 'r':
  61.                 return('\r');
  62.         case '0': case '1': case '2': case '3':
  63.         case '4': case '5': case '6': case '7':
  64.                 octv = c-'0';
  65.                 for (n = 1; (c = lexchar())>='0' && c<='7' && n<=3; n++)
  66.                         octv = octv*010 + (c-'0');
  67.                 ungetc(c, lexin);
  68.                 return(octv);
  69.         case '\n':
  70.  
  71.                 yyline++;
  72.                 return(mapch(delim, esc));
  73.         }
  74.         return(c);
  75. }
  76.